package body Plaques is

	function Get_Id (P : Plaque) return Natural is
	begin
		return P.Id;
	end Get_Id;
	
	function Get_Position (P : Plaque) return Dimension is
	begin
		return P.Position;
	end Get_Position;

	procedure Set_Position (P : in out Plaque; Position : in Dimension) is
	begin
		P.Position := Position;
	end Set_Position;
	
	function Get_Taille (P : Plaque) return Dimension is
	begin
		return P.Taille;
	end Get_Taille;

	procedure Set_Taille (P : in out Plaque; Taille : in Dimension) is
	begin
		P.Taille := Taille;
	end Set_Taille;

	function Get_Categorie (P : Plaque) return Categories.Ptr_Categorie is
	begin
		return P.Cat;
	end Get_Categorie;

    function Creer (Id : Natural;
    				Cat : Categorie_Verre) return Plaque is
		C : Categories.Ptr_Categorie;
	begin
		C := Liste_Categories.Get_Categorie(Cat);
		return Plaque'(Id, C, Categories.Get_Taille(C), Position=>Dim(0,0));
	end Creer;
                    
    function Creer (Mere : Plaque;
    				Taille : Dimension;
    				Position : Dimension) return Plaque is
	begin
		return Plaque'(
			Id => Mere.Id,
			Cat => Mere.Cat,
			Taille => Taille,
			Position => Position);
	end Creer;
    
    function Creer (Piece_Mere : Pieces.Piece) return Plaque is
        Empl_Piece : Emplacements.Emplacement := Pieces.Get_Emplacement(Piece_Mere);
    begin
        return Plaque'(
            Id => Emplacements.Get_Id_Plaque(Empl_Piece),
            Cat => Pieces.Get_Categorie(Piece_Mere),
            Taille => Pieces.Get_Dimension(Piece_Mere),
            Position => Emplacements.Get_Position(Empl_Piece)
            );
    end Creer;
    				
	function Est_Valide (P : Plaque) return Boolean is
	begin
		null; return true;
	end Est_Valide;
	
	function Peut_Accueillir (P : Plaque; Piece : Pieces.Piece) return Boolean is
	begin
		return (Pieces.Get_Dimension(Piece) < P.Taille) and (Pieces.Get_Categorie(Piece) = P.Cat);
	end Peut_Accueillir;
	
	function Comparer (A,B : Plaque) return Boolean is
	begin
		if Get_Categorie(A) /= Get_Categorie(B) then
			return Get_Categorie(A) > Get_Categorie(B);
		else
			return Get_Id(A) > Get_Id(B);
		end if;
	end Comparer;
	
	function ToString (P : Plaque) return String is
	begin
		return ("Id: " & Natural'Image(P.Id) & " Cat: " & Categories.Get_Categorie_Verre(P.Cat) & " Taille: " & ToString(P.Taille) & " Position: " & ToString(P.Position));
	end ToString;
	
	
end Plaques;